package com.ruoyi.gis.geoserver.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.framework.gis.GeoserverConfig;
import com.ruoyi.gis.geoserver.service.GeoserverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.net.MalformedURLException;
import java.util.List;

@RestController
@RequestMapping("/geoserver")
public class GeoServerController {
    @Autowired
    private GeoserverService geoserverService;
    @Autowired
    private GeoserverConfig geoserverConfig;


    @GetMapping("/list/workspaces")
    public AjaxResult listAllWorkspace() throws MalformedURLException {
        List<String> list = geoserverService.listWorkspace();
        return AjaxResult.success(list);
    }

    @GetMapping("/list/{workspace}/stores")
    public AjaxResult listAllWorkspaceStore(@PathVariable("workspace")String workspace ) throws MalformedURLException {
        List<String> list = geoserverService.listWorkspaceStore(workspace);
        return AjaxResult.success(list);
    }

    @GetMapping("/list/{workspace}/{store}/layers")
    public AjaxResult listAllWorkspaceStore(@PathVariable("workspace")String workspace,
                                            @PathVariable("store")String store) throws MalformedURLException {
        List<String> list = geoserverService.listWorkspaceStoreLayers(workspace,store);
        return AjaxResult.success(list);
    }
}
